import React, { Component } from "react";
import { Route, Switch, Redirect } from "react-router-dom"
import Home from "./pages/Home"
import About from "./pages/About"
import MyNavLink from "./components/MyNavLink";
import Header from "./pages/Header";

export default class App extends Component {
  render() {
    return (
      <div>
        <Header />
        <div className="row">
          <div className="col-xs-2 col-xs-offset-2">
            <div className="list-group">
              {/* 原生的使用<a>标签实现页面跳转 */}
              {/* <a className="list-group-item" href="./about.html">About</a>
              <a className="list-group-item active" href="./home.html">Home</a> */}

              {/* React中使用Link实现组件跳转 */}
              <MyNavLink to='/home'>Home</MyNavLink>
              <MyNavLink to='/about'>About</MyNavLink>
            </div>
          </div>
          <div className="col-xs-6">
            <div className="panel">
              <div className="panel-body">
                {/* 使用Switch组件包裹了Route组件后，匹配到一个组件就不会继续往下匹配，提高效率 */}
                <Switch>
                  {/* 注册路由 */}
                  <Route path="/home" component={Home} />
                  <Route path="/about" component={About} />
                  {/* 重定向路由，当页面路径都匹配不到时自动重定向到该路径 */}
                  <Redirect to="/home" />
                </Switch>
              </div>
            </div>
          </div>
        </div>
      </div>
    );
  }
}
